package com.dp.client.views.reportesCharts;

import java.util.Date;

import com.google.gwt.i18n.client.*;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.RootPanel;
import org.moxieapps.gwt.highcharts.client.*;
import org.moxieapps.gwt.highcharts.client.labels.*;
import org.moxieapps.gwt.highcharts.client.plotOptions.*;

public class CrearSplineUpdatingEachSecond {
	private Chart chart;
	private Point [] points;
	private String nombre;
	private String tipo;
	private String labelY;
	
	public CrearSplineUpdatingEachSecond(){
		init();
	}
	
	public CrearSplineUpdatingEachSecond(Point [] points, String nombre,String tipo){
		this.points=points;
		this.nombre=nombre;
		this.tipo=tipo;
		init();
	}
	public CrearSplineUpdatingEachSecond(String nombre,String labelY,String tipo){
		this.nombre=nombre;
		this.labelY=labelY;
		this.tipo=tipo;
		init();
	}
	private void init() {
		chart = new Chart()
        .setType(Series.Type.SPLINE)
        .setMarginRight(10)
        .setChartTitleText(nombre)
        .setBarPlotOptions(new BarPlotOptions()
            .setDataLabels(new DataLabels()
                .setEnabled(true)
            )
        )
        .setLegend(new Legend()
            .setEnabled(false)
        )
        .setCredits(new Credits()
            .setEnabled(false)
        )
        .setToolTip(new ToolTip()
            .setFormatter(new ToolTipFormatter() {
                public String format(ToolTipData toolTipData) {
                    return "<b>" + toolTipData.getSeriesName() + "</b><br/>" +
                        DateTimeFormat.getFormat("yyyy-MM-dd "/*HH:mm:ss"*/)
                            .format(new Date(toolTipData.getXAsLong())) + "<br/>" +
                        NumberFormat.getFormat("0.00").format(toolTipData.getYAsDouble());
                }
            })
        );

	    chart.getXAxis()
	        .setType(Axis.Type.DATE_TIME)
	        .setTickPixelInterval(150);
	
	    chart.getYAxis()
	        .setAxisTitleText(labelY)
	        .setPlotLines(
	            chart.getYAxis().createPlotLine()
	                .setValue(0)
	                .setWidth(1)
	                .setColor("#808080")
	        );
		
	}
	Chart getChart(){
		return chart;
	}
}
